-module(log).
-compile(export_all).
nowt()->
  {{Y,M,D},{HH,MM,SS}} = calendar:local_time(),
  [{Y,M,D},{HH,MM,SS}].
 
time_out()->
	{{Y,M,D},{HH,MM,SS}} = erlang:localtime(),
	io:fwrite("[~4.10B-~2.10.0B-~2.10.0B ~2.10.0B:~2.10.0B:~2.10.0B] ",[Y,M,D,HH,MM,SS]),
	save_log("[~4.10B-~2.10.0B-~2.10.0B ~2.10.0B:~2.10.0B:~2.10.0B] ",[Y,M,D,HH,MM,SS]).

save_log(Format)->
	IS = get(savelog),
	if
	 IS =:= true ->
		Dev = get(logfile),
		io:fwrite(Dev,Format,[]);
	true->
		ok
	end.
save_log(Format,Data)->
	
	IS = get(savelog),
	if
	 IS =:= true ->
		Dev = get(logfile),
		io:fwrite(Dev,Format,Data);
	true->
		ok
	end.
log_out(Format)->
	time_out(),
	io:fwrite(Format),
	save_log(Format).
log_out(Format,Data)->
	time_out(),
	io:fwrite(Format,Data),
	save_log(Format,Data).
log_out(IODevice,Format,Data)->
	time_out(),
	io:fwrite(IODevice,Format,Data).
